﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Yipusoft.SoldierArchives.Model;
using Yipusoft.SoldierArchives.BLL;
using Yipusoft.SoldierExam.BLL;
using Yipusoft.SoldierExam.Model;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;

public partial class SoldierArchives_SoldierScore : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            #region 权限
            bool isPermission = false;
            if (Yipusoft.Account.BLL.User.HasPermission(User.Identity.Name, "300300"))
            {
                isPermission = true;
            }
            else
            {

                if (Yipusoft.Account.BLL.User.HasPermission(User.Identity.Name, "300308"))
                {
                    isPermission = true;
                }

            }

            #endregion
            if (!isPermission)
            {
                Response.Write("<script> alert('没有权限!');window.close();</script>");
                return;
            }
            else
            {


                Soldier soldierBll = new Soldier();
                SoldierArchiveInfo soldier = soldierBll.GetSoldierInfoByID(Request["SoldierID"]);
                lblSoldierName.Text = soldier.SoldierName;
                lblDepartmentName.Text = soldier.DepartmentName;

                lblRanger.Text = AptitudeRanger.GetRangerById(int.Parse(Request["RangerID"])).Ranger;
                int ExamID = int.Parse(Request["ExamID"]);
                AptitudeExamInfo ExamInfo = AptitudeExam.GetAptitudeExamInfo(ExamID);
                string pp = "";
                if (ExamInfo != null)
                {
                    pp = ExamInfo.Subject;
                }
                lblTitle.Text = pp;
                TimeSpan ts = DateTime.Today.Subtract(soldier.Birthday);
                lblAge.Text = Convert.ToString(Math.Floor(ts.TotalDays / 365) + 1);

                DlTiNeng.DataSource = AptitudeItem.GetListBySkill("ZZKH010100");
                DlTiNeng.DataBind();
                JiNeng.DataSource = AptitudeItem.GetListBySkill("ZZKH010200");
                JiNeng.DataBind();
                AptitudeExamScoreInfo info = AptitudeExamScore.GetAptitudeExamScore(Request.QueryString["SoldierID"], Convert.ToInt32(Request.QueryString["RangerID"]), Convert.ToInt32(Request.QueryString["ExamID"]), 13);

                if (info != null)
                {
                    Score13.Text = info.Score.ToString();

                    AptitudeStandardInfo stInfo = AptitudeStandard.GetStandardById(int.Parse(Request["StandardID"]));
                    lblZongHe.Text = stInfo.Standard == 1 ? "合格" : "不合格";
                    lblNote.Text = AptitudeRanger.GetRangerById(int.Parse(Request["RangerID"])).Note;
                }
            }
        }
    }

    AptitudeExamScoreInfo GetExamScoreByItemCode(string ItemCode)
    {
        List<AptitudeExamScoreInfo> list1 = AptitudeExamScore.getList(Request["SoldierID"], int.Parse(Request["RangerID"]), int.Parse(Request["ExamID"]));
        AptitudeItemInfo item = AptitudeItem.GetAptitudeItemByCode(ItemCode);
        return (from pp in list1 where pp.ItemID == item.ItemID select pp).Single();
    }

    private string GetStandard(string standard)
    {
        string ret = "";
        switch (standard)
        {
            case "-1":
                ret = "否";
                break;
            case "0":
                ret = " ";
                break;
            case "1":
                ret = "是";
                break;
        }
        return ret;
    }
    protected void DlTiNeng_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            AptitudeItemInfo itemInfo = e.Item.DataItem as AptitudeItemInfo;
            Label Result = e.Item.FindControl("Result") as Label;
            Label Score = e.Item.FindControl("Score") as Label;
            AptitudeExamScoreInfo info = AptitudeExamScore.GetAptitudeExamScore(Request.QueryString["SoldierID"], Convert.ToInt32(Request.QueryString["RangerID"]), Convert.ToInt32(Request.QueryString["ExamID"]), Convert.ToInt32(itemInfo.ItemID));
            if (info != null)
            {
                Result.Text = info.Result;
                Score.Text = info.Score.ToString();
            }
        }
    }
    protected void JiNeng_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            AptitudeItemInfo itemInfo = e.Item.DataItem as AptitudeItemInfo;
            Label Result = e.Item.FindControl("Result") as Label;
            Label Stand = e.Item.FindControl("Stand") as Label;
            AptitudeExamScoreInfo info = AptitudeExamScore.GetAptitudeExamScore(Request.QueryString["SoldierID"], Convert.ToInt32(Request.QueryString["RangerID"]), Convert.ToInt32(Request.QueryString["ExamID"]), Convert.ToInt32(itemInfo.ItemID));
            if (info != null)
            {
                Result.Text = info.Result;
                Stand.Text = GetStandard(info.Standard.ToString());
            }
        }
    }
}
